// pages/my/my.js
Page({
  data: {
    userInfo: {
      realName: '',
      id: '',
      classes: '',
      avatar:''
    },
    username:''
  },

  onLoad: function() {
    var username = wx.getStorageSync('username');
    if (username) {
      this.setData({
        username: username
      });
    }
    this.fetchUserInfo();
  },

  // 从后端获取用户信息
  fetchUserInfo: function() {
    
    wx.request({
      url: 'http://192.168.172.134:5000/api/user', // 后端 API 地址
      method: 'GET',
      data: { username: this.data.username },
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            userInfo: res.data
          });
        } else {
          wx.showToast({
            title: '数据获取失败',
            icon: 'none'
          });
        }
      },
      fail: (err) => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  },

  // 跳转到简历页面
  navigateToResume: function() {
    wx.navigateTo({
      url: '/pages/resume/resume'
    });
  },

  // 跳转到修改密码页面
  navigateToChangePassword() {
    wx.navigateTo({
      url: '/pages/change-password/change-password'
    })
  },

  //跳转到就业状态页面
  navigateToEmploy(){
    wx.navigateTo({
      url: '/pages/employmentStatus/employmentStatus'
    })
  },

  navigateToEditProfile() {
    wx.navigateTo({
      url: '/pages/user_editor/user_editor'
    });
  },

  // 退出登录
  logout: function() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: function(res) {
        if (res.confirm) {
          wx.redirectTo({
            url: '/pages/login/login'
          });
        }
      }
    });
  }
});